home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / c-tools / c_examples / led / led.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-03  |  3.2 KB  |  111 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // Led.cpp
  3. //
  4. // Deryk Robosson
  5. // April 25, 1996
  6. //
  7. // 5.23.96 DBR
  8. // SetDigits(int pair, int number)
  9. //////////////////////////////////////////////////////////////////////////////
  10.  
  11. //////////////////////////////////////////////////////////////////////////////
  12. // INCLUDES
  13. #include "aframe:include/Led.hpp"
  14.  
  15. //////////////////////////////////////////////////////////////////////////////
  16. //
  17.  
  18. // Open led.image if it's not already open =)
  19. AFLed::AFLed()
  20. {
  21.     int i;
  22.  
  23.     m_Global.Added=FALSE;
  24.     m_Global.Image=NULL;
  25.     m_Global.Colon=TRUE;
  26.     m_Global.Negative=FALSE;
  27.     m_Global.Signed=TRUE;
  28.     m_Global.FGPen=1;
  29.     m_Global.BGPen=0;
  30.     m_Global.NumPairs=1;
  31.     m_Global.Window=NULL;
  32.     m_Global.Image=NULL;
  33.     LedLibrary=NULL;
  34.  
  35.     for(i=0;i<m_Global.NumPairs;i++)
  36.         m_Global.DigitPairs[i]=0;
  37.  
  38.     if(LedLibrary == NULL)
  39.         if(!(LedLibrary=(struct ClassLibrary*)OpenLibrary((UBYTE*)"images/led.image",(ULONG)37)))
  40.             if(!(LedLibrary=(struct ClassLibrary*)OpenLibrary((UBYTE*)":classes/images/led.image",(ULONG)37)))
  41.                 if(!(LedLibrary=(struct ClassLibrary*)OpenLibrary((UBYTE*)"classes/images/led.image",(ULONG)37)))
  42.                     printf("Failed to open led.image\n");
  43. }
  44.  
  45. AFLed::~AFLed()
  46. {   // Call DestroyObject if it hasn't already
  47.     if(m_Global.Image != NULL)
  48.         DestroyObject();
  49. }
  50.  
  51. // Remove object from window if it has been added
  52. // and dispose of it
  53. void AFLed::DestroyObject()
  54. {
  55.     RemoveObject();
  56.  
  57.     if(LedLibrary) {
  58.         CloseLibrary((struct Library*)LedLibrary);
  59.         LedLibrary=NULL;
  60.     }
  61. }
  62.  
  63. // Add object to a window, with size and position of rect
  64. BOOL AFLed::Create(AFWindow *window, AFRect *rect)
  65. {
  66.     if(m_Global.Added)
  67.         RemoveObject();
  68.  
  69.     if(m_Global.Image=(struct Image*)NewObject((struct IClass*)NULL, (UBYTE*)"led.image",
  70.                         IA_FGPEN, m_Global.FGPen,
  71.                         IA_BGPen, m_Global.BGPen,
  72.                         IA_Width, rect->Width(),
  73.                         IA_Height, rect->Height(),
  74.                         LED_Pairs, m_Global.NumPairs,
  75.                         LED_Values, m_Global.DigitPairs,
  76.                         LED_Colon, m_Global.Colon,
  77.                         LED_Negative, m_Global.Negative,
  78.                         LED_Signed, m_Global.Signed,
  79.                         ICA_TARGET, ICTARGET_IDCMP,
  80.                         TAG_DONE)) {
  81.         AddGadget(window->m_pWindow, (struct Gadget*)m_Global.Image, -1);
  82.  
  83.         DrawImage(window->m_pWindow->RPort, m_Global.Image, rect->TopLeft()->m_x, rect->TopLeft()->m_y);
  84.  
  85.         m_Global.Window=window;
  86.         m_Global.Added=TRUE;
  87.         m_Global.rect.SetRect(rect->TopLeft(),rect->BottomRight());
  88.         return TRUE;
  89.     } else return FALSE;
  90. }
  91.  
  92. // Remove object from the window to which it was added
  93. void AFLed::RemoveObject()
  94. {
  95.     if(m_Global.Image !=NULL) {
  96.         DisposeObject((Object*)m_Global.Image);
  97.         m_Global.Image=NULL;
  98.     }
  99. }
  100.  
  101. void AFLed::RefreshImage()
  102. {
  103.     DrawImage(m_Global.Window->m_pWindow->RPort, m_Global.Image, m_Global.rect.TopLeft()->m_x, m_Global.rect.TopLeft()->m_y);
  104. }
  105.  
  106. void AFLed::SetDigits(int pair, int number)
  107. {
  108.     m_Global.DigitPairs[pair]=number;
  109.     Create(m_Global.Window, &m_Global.rect);
  110. }
  111.